﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JsApiPayPage.aspx.cs" Inherits="WAD.Client2.Client2.API.JsApiPayPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title></title>
</head>

<body>
    <form id="form1" runat="server">
        <br />

    </form>
    <script type="text/javascript">
        var backUrl = '<%=BackUrl%>';
        var okUrl = '<%=OkUrl%>';
        //调用微信JS api 支付
        function jsApiCall()
        {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                <%=wxJsApiParam%>,//josn串
                    function (res) {
                        if (res.err_msg === "get_brand_wcpay_request:ok") {
                            window.location.href = okUrl;
                        }else if (res.err_msg === "get_brand_wcpay_request:cancel") {
                            window.location.href = backUrl;
                        }else if (res.err_msg === "get_brand_wcpay_request:fail") {
                            alert("支付失败！");
                            window.location.href = backUrl;
                        } else {
                            alert("系统支付遇到未知错误！");
                            window.location.href = backUrl;
                        }
                    }
            );
        }

               
        if (typeof WeixinJSBridge == "undefined")
        {
            if (document.addEventListener)
            {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }
            else if (document.attachEvent)
            {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }
        else
        {
            jsApiCall();
        }
               
               
    </script>
</body>
</html>
